package com.qidian.md.controller;

import com.qidian.md.service.WorkstationService;
import com.qidian.mes.pojo.md.Workstation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 18林梦雅
 * @Company 起点编程
 * @Time 2023/10/31 19:42
 * @Description
 */
@RestController
@RequestMapping("/workstation")
@CrossOrigin
public class WorkstationController {

    @Autowired
    WorkstationService workstationService;


    /**
     * 多条件查询信息
     * @param workstation
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public MESResult list(Workstation workstation, @RequestParam(defaultValue="1")int page, @RequestParam(defaultValue="10")int limit){
        System.out.println(workstation+"++++++++++++++++++++++++++++++++++++++++++");
        return workstationService.queryByPage(workstation,page,limit);
    }

    /**controller
     * 添加工作站接口
     * 请求方法： POST
     * url： /workstation/save
     * 参数：
     * 格式：JSON
     * 参数的内容：workstationname,workstationPass
     * 响应结果：
     * 成功： ｛code:200,msg:"",data:null｝
     * 失败：
     * 失败｛code:500,msg:"错误信息",data:null｝
     * 重名 {code: 300,msg:"名字重复",data:""}
     * @param workstation
     * @return
     */
    @PostMapping("/save")
    public MESResult save(@RequestBody Workstation workstation){
        return workstationService.addWorkstation(workstation);
    }


    /**controller
     * 请求方法： GET
     * url : /workstation/get
     * 参数： workstationId(必须，要查询的工作站编号)
     * 响应：
     *  成功： `{code:200,msg:"",data:{workstationId:1,workstationname:"大锤",workstationPass:"123".....}}`
     *  失败：`{code:400,msg:"没有数据",data:null}`
     * @param workstationId
     * @return
     */
    @GetMapping("/get")
    public MESResult get(Long workstationId){
        return   workstationService.queryById(workstationId);
    }

    /**编辑工作站
     请求方法： PUT/POST
     url： /workstation/edit
     参数 : workstationId(必须),workstationname,workstationPass,workstationStatus
     响应结果：
     成功： ｛code:200,msg:"",data:null｝
     失败：
     失败｛code:500,msg:"错误信息",data:null｝
     重名 {code: 300,msg:"名字重复",data:""}
     */
    @PutMapping("/update")
    public MESResult update(@RequestBody Workstation workstation){
        System.out.println(workstation+"+++++++++++++++++++++++++++++++++++++++++");
        return workstationService.update(workstation);
    }

    /**
     * 根据Id删除工作站数据,删除是将是否启用改为0,将搜索显示是更改为除了0其他显示
     * @param workstationId
     * @return
     */
    @DeleteMapping("/{workstationId}")
    public MESResult deleteById(@PathVariable Long workstationId){//注意这里的注解是因为用字段为url
        return workstationService.deleteUpdateStatus(workstationId);
    };


    /**
     * 批量删除,将启用状态变为0
     * @param workstationId
     * @return
     */
    @DeleteMapping("/deletes")
    public MESResult deleteSelect( Long[] workstationId){
        System.out.println(workstationId+"+++++++++++++++++++++++++++++++++++++++++++++++");
        return workstationService.deleteUpdateSelect(workstationId);
    };

}
